{extend name="admin/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<style type="text/css">
.fun-a {
	margin-top: 0px;
	padding: 6px 15px 0 15px;
}
.style0list tbody td a{
	margin-left: 8px;
}
.num{width:40px;text-align:center;}	
.cell_total{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;width:250px;display: block;}
.style0list table input {
	margin-bottom: 0px;
}

.style0list table input.sort {
	width: auto;
	text-align: center;
}

.style0list tbody td {
	line-height: 28px;
}
</style>
{/block}
{block name="right_tab"}
<li><a class="nscs-table-handle_green" href="{:__URL('ADMIN_MAIN/config/addlink')}" ><i class="fa fa-plus-circle"></i>&nbsp;添加友情链接</a></li>
{/block}
{block name="main"}
<div class="operation">
	<a class="btn btn-small fun-a" href="javascript:batchDelete()">批量删除</a>
</div>
<div class="mod-table">
	<div class="con style0list">
		<table>
			<colgroup>
				<col style="width: 1%">
				<col style="width: 8%;">
				<col style="width: 10%;">
				<col style="width: 15%;">
				<col style="width: 20%;">
				<col style="width: 12%;">
				<col style="width: 10%;">
				<col style="width: 20%;">
				<col style="width:auto">
			</colgroup>
			<thead>
				<tr align="center">
					<th><label><input value="" name="" id="ckall" type="checkbox" onClick="CheckAll()"></label></th>
					<th class="x-tab"><div class="iconbg-arrow up">排序</div></th>
					<th class="x-tab tal"><div class="iconbg-arrow up">链接名称</div></th>
					<th class="x-tab tal"><div class="iconbg-arrow up">链接地址</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">是否打开新窗口</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">是否显示</div></th>
					<th class="x-tab"><div class="iconbg-arrow up">图片</div></th>
					<th class="x-tab">操作</th>
				</tr>
			</thead>
			<tbody id="linkList"></tbody>
		</table>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
//全选
function CheckAll(){
	if($("#linkList input[type = 'checkbox']").attr("checked")){
		$("#linkList input[type = 'checkbox']").attr("checked",false);
	}else{
		$("#linkList input[type = 'checkbox']").attr("checked",true);
	}
}

//分页数据
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/linklist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val()
		},
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data['data'][i]['link_id']+'" ></label></div></td>';
					//html += '<td><input type="text" min="0" value="'+ data["data"][i]["link_sort"]+'"  nav_id="'+ data['data'][i]['link_id']+'" class="num" ></td>';
					html += '<td><span>'+ data["data"][i]["link_sort"]+'</span></td>';
					html += '<td class="cell_total tal" title="'+data["data"][i]["link_title"]+'">' + data["data"][i]["link_title"]+ '</td>';
					html += '<td class="tal">' + data["data"][i]["link_url"]+ '</td>';
					if(data["data"][i]["is_blank"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class"><i class="fa fa-check text-success text-active"></i></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class"><i class="fa fa-times text-danger text"></i></a></td>';
						
					}
					if(data["data"][i]["is_show"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class"><i class="fa fa-check text-success text-active"></i></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class"><i class="fa fa-times text-danger text"></i></a></td>';
					}
					
					
					if(data["data"][i]["link_pic"] != ''){
						html += '<td><image src=__UPLOAD__/' + data["data"][i]["link_pic"]+ ' style="width:100px;"></td>';
					}else{
						html += '<td></td>';
					}
					html += '<td><a href="'+__URL('ADMIN_MAIN/config/updatelink?link_id='+ data['data'][i]['link_id'])+'">修改</a><a style="cursor: pointer;" onclick="deleteLink('+data['data'][i]['link_id']+')">删除</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><th colspan="9">暂无友情链接</th></tr>';
			}
			$(".style0list tbody").html(html);
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}


function batchDelete() {
	var link_id= new Array();
	$(".style0list tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			link_id.push($(this).val());
		}
	});
	if(link_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#e57373": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deleteLink(link_id);
}
function deleteLink(link_id){
	$( "#dialog" ).dialog({
		buttons: {
		"确定": function() {
		$(this).dialog('close');
			$.ajax({
			type:"post",
			url:"{:__URL('ADMIN_MAIN/config/dellink')}",
			data:{ 'link_id':link_id.toString() },
			success:function (data) {
				if(data['code'] > 0){
					LoadingInfo(getCurrentIndex(link_id,'.style0list tbody'));
					showMessage('success', data["message"]);
				}else{
					showMessage('error', data["message"]);
				}
			}
		});
	},
	"取消,#e57373": function() {
		$(this).dialog('close');
	}
	},
	contentText:"确定删除？",
	});
}
</script>
{/block}